from pathlib import Path

# === 动态获取项目根目录 ===
current_file = Path(__file__).resolve()
project_root = current_file.parents[1]  # 父级的父级（testcase -> UGC_UI）

# === 基础目录（reports总目录，使用Path对象） ===
REPORT_DIR = project_root / "reports"

# === reports子目录细分（所有子目录均为Path对象） ===
REPORT_HTML_DIR = REPORT_DIR / "html_reports"
REPORT_LOGCAT_DIR = REPORT_DIR / "logcat_logs"
REPORT_SCRIPT_LOG_DIR = REPORT_DIR / "script_logs"
BASELINE_DIR = REPORT_DIR / "baseline"
CLEANUP_DIR = REPORT_DIR / "cleanup_screenshots"
CRASH_LOG_DIR = REPORT_DIR / "crash_logs"
AIR_DIR = project_root / "air"
CASE_SCREENSHOT_DIR = REPORT_DIR / "case_screenshot"
PERFORMANCE_REPORT_DIR = REPORT_DIR / "performance_reports"
SUMMARY_REPORT_DIR = REPORT_DIR / "summary_reports"
RECORDING_DIR = REPORT_DIR / "screen_recordings"

# === 设备配置（改为动态获取） ===
DEVICE_URI = None  # 将在运行时确定

# === 全局状态 ===
INTERRUPTED = False

# 性能监控调试模式
PERF_MONITOR_DEBUG = True

# 应用启动超时时间（秒）
APP_START_TIMEOUT = 30

# === 新增配置开关 ===
ENABLE_LOGCAT = True  # 是否启用logcat日志抓取
ENABLE_PERF_MONITOR = True  # 是否启用性能监控
ENABLE_RECORDING = False  # 是否启用录屏功能

# === 基准图路径 ===
BASELINE_PATH = BASELINE_DIR / "baseline.png"

# === 录屏配置 ===
 # 本地录屏文件存放目录
MAX_RECORDING_TIME = 1800  # 最大录屏时间（秒）
DEVICE_RECORDING_DIR = "/sdcard/Android/data/tmp_recordings/"  # 设备上临时存放录屏的目

# === 初始化目录（确保所有子目录存在） ===
for dir_path in [
    REPORT_HTML_DIR, REPORT_LOGCAT_DIR, REPORT_SCRIPT_LOG_DIR,
    BASELINE_DIR, CLEANUP_DIR, CRASH_LOG_DIR, AIR_DIR,
    CASE_SCREENSHOT_DIR, PERFORMANCE_REPORT_DIR, SUMMARY_REPORT_DIR, RECORDING_DIR
]:
    dir_path.mkdir(parents=True, exist_ok=True)

# 性能阈值配置
PERFORMANCE_THRESHOLDS = {
    "rss_memory": {
        "avg": 450 * 1024,  # 平均物理内存不超过450MB (单位: KB)
        "peak": 600 * 1024  # 峰值物理内存不超过600MB
    },
    "virt_memory": {
        "avg": 9 * 1024 * 1024,  # 平均虚拟内存不超过9GB (单位: KB)
        "peak": 10 * 1024 * 1024 # 峰值虚拟内存不超过10GB
    },
    "cpu": {
        "avg": 200,          # 平均CPU使用率不超过200%
        "peak": 400          # 峰值CPU使用率不超过400%
    },
    "fps": {
        "avg": 45,           # 平均FPS不低于45
        "min": 30            # 最低FPS不低于30
    },
    "temperature": {
        "peak": 45           # 峰值温度不超过45°C
    },
    "memory_leak": {
        "growth_rate": 50,   # 内存增长速率不超过50KB/秒
        "max_increase": 300 * 1024  # 内存最大增长不超过300MB
    }
}